#include<iostream>
#include<algorithm>
using namespace std;

const int N=1e6+10;
int heap[N];
int n;

void up(int child)//向上调整算法
{
	int parent=child/2;
	while(parent>=1&&heap[parent]<heap[child])
	{
		swap(heap[child],heap[parent]);
		child=parent;
		parent=child/2;
	}
}

void down(int parent)//向下调整,父节点和较大的子节点比较，如果小于互换
{
	int child=parent*2;
	while(child<=n)
	{
		if(child+1<=n&&heap[child+1]>heap[child]) child++;
		if(heap[parent]>heap[child]) return;
		swap(heap[child],heap[parent]);
		parent=child;
		child=parent*2;
	}
}
void push(int x)
{
	heap[++n]=x;
	up(n);
}
// 删除堆顶元素
void pop()
{
    swap(heap[1], heap[n]);
    n--;
    down(1);
}

// 查询堆顶元素
int top()
{
    return heap[1];
}

// 堆的大小
int size()
{
    return n;
}
int main()
{
	int a[10] = {1, 41, 23, 10, 11, 2, -1, 99, 14, 0};

    // 将这 10 个数依次放入堆中
    for(int i = 0; i < 10; i++)
    {
        push(a[i]);
    }

    while(size())
    {
        cout << top() << " ";
        pop();
    }
	return 0;
}